package com.caidan.comsumer.controller;


import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

/**
 * @项目名 rabbit-mq-learning
 * @描述 接受消息
 * @作者 wzy
 * @时间 2024/5/18 18:16
 */
@Component
@Slf4j
public class AcceptMessage {
    //    @RabbitListener(queues = "work.queue1")
//    public void listenSimpleQueue1(String msg){
//        System.out.println("work.queue1 - 传递的消息是msg = " + msg);
//    }
//    @RabbitListener(queues = "work.queue1")
//    public void listenSimpleQueue2(String msg){
//        System.err.println("work.queue1 - 传递的消息是msg = " + msg);
//    }
//    @RabbitListener(queues = "hello.queue3")
//    public void listenSimpleQueue3(String msg){
//        System.out.println("hello.queue3 - 传递的消息是msg = " + msg);
//    }
//    @RabbitListener(queues = "fanout.queue1")
//    public void listenSimpleQueue1(String msg) {
//        System.out.println("fanout.queue1 - 传递的消息是msg = " + msg);
//    }
//
//    @RabbitListener(queues = "fanout.queue2")
//    public void listenSimpleQueue2(String msg) {
//        System.out.println("fanout.queue2 - 传递的消息是msg = " + msg);
//    }
//
//    @RabbitListener(bindings = @QueueBinding(
//            value = @Queue(name = "direct.queue1",durable = "true"),
//            exchange = @Exchange(name = "hmall.direct",type = "direct"),
//            key = {"red","blue"}
//    ))
//    public void listenDirectQueue1(String msg) throws InterruptedException{
//        System.out.println("消费者A收到了队列的消息 msg = " + msg);
//    }

////    这个是fanout类型交换机
//    @RabbitListener(queues = "fanout.queue1")
//    public void queue1(String msg) {
//        System.out.println("queue1接受消息" + msg);
//    }
//
//    @RabbitListener(queues = "fanout.queue2")
//    public void queue2(String msg) {
//        System.out.println("queue2接受消息" + msg);
//    }
//    这个是Direct交换机中的内容
//    @RabbitListener(queues = "direct.queue1")
//    public void directQueue1(String msg){
//        log.info("输出交换机中接受的信息{}",msg);
//    }
//
//    @RabbitListener(queues = "direct.queue2")
//    public void directQueue2(String msg){
//        log.info("输出交换机中接收的信息{}",msg);
//    }
//    这个是topic交换机的内容
//    @RabbitListener(queues = "topic.queue1")
//    public void topicQueue1(String msg){
//        log.info("topicQueue1消息接收{}",msg);
//    }
//    @RabbitListener(queues = "topic.queue2")
//    public void topicQueue2(String msg){
//        log.info("topicQueue2消息接收{}",msg);
//    }

//    基于注解的绑定队列
//    @RabbitListener(bindings = @QueueBinding(
//            value = @Queue(value = "direct.queue1", durable = "true"),
//            exchange = @Exchange(name = "hmall.direct", type = ExchangeTypes.DIRECT),
//            key = {"red", "blue"}
//    ))
//    public void directQueue(String msg){
//        log.info("这个内容可以绑定多个routingKey，" +
//                "可以使用这个内容进行多个绑定，从而简化书写内容");
//    }
    @RabbitListener(queues = "lax.queue")
    public void DeadMessage(String msg){
        log.info("接受到消息{}",msg);
    }
}